;ledbpgp2s.compensated.dn
;avance-version (23/10/22)
;
;2D sequence for diffusion measurement using stimulated 
;   echo and LED
;using bipolar gradient pulses for diffusion
;using 2 spoil gradients and a compensating gradient
;optional solvent presaturation using pulsed presat or changing frequencies 
;during relaxation and diffusion delays

;G. Peat, P.J. Boaler, C.L. Dickson, G.C. Lloyd-Jones & D. Uhrin, Nat. Commun., 2023. 
;
; based on BRUKER ledbpgp2s
;D. Wu, A. Chen & C.S. Johnson Jr., J. Magn. Reson. A 115, 260-264 (1995).
;Pelta, MD, Morris, GA, Stchedroff, MJ and Hammond, SJ. Magn. Reson. Chem. 40:S147-S152 (2002)

;solvent suppression based on
;Kew, W., Bell, N.G.A. Goodall, I., Uhrin, D., Magn. Reson. Chem. 55, 785-796, (2017)

;For mutli-resonance suppression use Multi-reson-suppress.xlsx and PresatOptimise.jl to optimise p23 and o1
 
;$CLASS=HighRes
;$DIM=2D
;$TYPE=
;$SUBTYPE=
;$COMMENT=


#include <Avance.incl>
#include <Grad.incl>
#include <Delay.incl>
#include <De.incl>

define list<gradient> diff=<Difframp>

"p2=p1*2"
"d11=30m"
"d12=20u"

# ifdef PULSED_PRESAT
"FACTOR1=(d1/(p23))+ 0.5"
"l6=FACTOR1"
# endif

# ifdef PULSED_PRESAT1
"FACTOR2=(d20/(p24))+ 0.5"
"l7=FACTOR2"
"d22=l7*p24"
# endif

# ifdef PRESAT1

# ifdef PULSED_PRESAT1
"DELTA1=d22-p1*2-p2-p30*2-d16*4-p19*2-2*d12"
# endif

# ifdef PRESAT_JUMP1
"DELTA1=d20-p1*2-p2-p30*2-d16*4-p19*2-d12*4-4u"
# endif

# else
"DELTA1=d20-p1*2-p2-p30*2-d16*4-p19*2"
# endif

"DELTA2=d21-p19-d16-4u"

"acqt0=-p1*2/3.1416"

1 ze

2 d11
  50u BLKGRAD

# ifdef PRESAT

# ifdef PULSED_PRESAT
  d12 pl0:f1
3 (p23:sp23 ph29):f1
  2u
  lo to 3 times l6
  d12 pl1:f1
# endif

#ifdef PRESAT_JUMP
  d12  fq=cnst23(bf):f1 ;solvent offset in Hz
  d12 pl9:f1
  d1 cw:f1 ph29
  4u do:f1
  d12 pl1:f1
  d12  fq=cnst24(bf):f1 ; real offset o1 in Hz
#endif

# else
  d1 pl1:f1
#endif

  50u UNBLKGRAD

  p19:gp7*-1
  d16
  p1 ph1
  p30:gp6*diff
  d16
  p2 ph1
  p30:gp6*-1*diff
  d16
  p1 ph2
  p19:gp7
  d16

# ifdef PRESAT1

# ifdef PULSED_PRESAT1
  d12 pl0:f1
4 (p24:sp24 ph29):f1
  2u
  lo to 4 times l7
  d12 pl1:f1
# endif

#ifdef PRESAT_JUMP1
  d12  fq=cnst23(bf):f1 ;solvent offset in Hz
  d12 pl9:f1
  DELTA1 cw:f1 ph29
  4u do:f1
  d12 pl1:f1
  d12  fq=cnst24(bf):f1 ; real offset o1 in Hz
#endif

# else
  DELTA1 pl1:f1
#endif

  p19:gp8*-1
  d16
  p1 ph3
  p30:gp6*diff
  d16
  p2 ph1
  p30:gp6*-1*diff
  d16
  p1 ph4
  p19:gp8
  d16
  DELTA2
  4u BLKGRAD
  p1 ph5
  go=2 ph31
  d11 mc #0 to 2 F1QF(igrad diff)
  DELTA1
exit


ph1= 0
ph2= 0 0 2 2
ph3= 0 0 0 0 2 2 2 2  1 1 1 1 3 3 3 3
ph4= 0 2 0 2 2 0 2 0  1 3 1 3 3 1 3 1
ph5= 0 0 0 0 2 2 2 2  1 1 1 1 3 3 3 3
ph29=0
ph31=0 2 2 0 2 0 0 2  3 1 1 3 1 3 3 1


;DIGMOD = baseopt
;pl1 : f1 channel - power level for pulse (default)
;pldb1 : f1 channel -  high power
;p1  : f1 channel -  90 degree high power pulse
;p2  : f1 channel - 180 degree high power pulse
;p19: gradient pulse 2 (spoil gradient)
;p30: gradient pulse (little DELTA * 0.5)
;d1  : relaxation delay; 1-5 * T1
;d11: delay for disk I/O [30 msec]
;d12: delay for power switching                         [20 usec]
;d16: delay for homospoil/gradient recovery             [200 usec]
;d20: diffusion time (big DELTA)
;d21: eddy current delay (Te)			[5 ms]
;NS: 8 * n
;DS: 4 * m
;td1: number of experiments
;FnMODE: QF
;        use xf2 and DOSY processing

;for presat during relaxation delay set
;zgoptns -DPRESAT -DPULSED_PRESAT or zgoptns -DPRESAT -DPRESAT_JUMP

;for presat during diffusion delay set
;zgoptns -DPRESAT1 -DPULSED_PRESAT1 or zgoptns -DPRESAT1 -DPRESAT_JUMP1

;for zgoptns -DPRESAT_JUMP set
;cnst23: signal to be suppressed [Hz]
;cnst24: o1 [Hz]

;for zgoptns -DPULSED_PRESAT set 
;p23 : ~50 ms low power rectangular pulse
;if off-resonance, calculate its exact length as desctiben in the Supplementary Information 

;if only one signal needs to be suppressed:
;SPNAM23 : Squa100.1000
;SPOFFS23 : resonance frequency of the suppressed signal minus o1 [Hz]
;spdb23 : use minimum power start with 60dB, asses the result

;if multiple signals need to be suppressed use Multi-reson-suppress.xlsx and PresatOptimise.jl to optimise p23 and o1
;create a phase-ramped shape using the calulated pulse length and the distances from o1
;prepare a rectangular shape and place it into the user library, e.g. Squa100.1000 (100us, 1000 points)
;on a topspin command line type:
;st manipulate /opt/topspin4.1/exp/stan/nmr/lists/wave/user/Squa100.1000 offs e 68936 3 565.73 -580.27 -754.27
;this will OVERWRITE the Squa100.1000 shape in /opt/topspin4.1/exp/stan/nmr/lists/wave/user/
;creating a 68936 us shape that will irradiate at 565.73, -580.27 and -754.27Hz away from optimised o1
;Note: for n frequencies replace 3 with n
;spdb23 : use minimum power, start with 60dB, asses the result. For every addtional frequency adjust by subtracting 6dB.

;for zgoptns -DPULSED_PRESAT1 repeat the process to set p24, SPNAM24, SPOFFS24 and spdb24, use shorter p24 (~ 10-20ms)

;use gradient ratio:    gp 6 : gp 7   : gp 8
;                       100  : -17.13 : -13.17

;for z-only gradients:
;gpz6: 100%
;gpz7: -17.13% (spoil)
;gpz8: -13.17% (spoil)

;use gradient files:   
;gpnam6: SINE.100
;gpnam7: SINE.100
;gpnam8: SINE.100

;use AU-program dosy to calculate gradient ramp-file Difframp
 
